// 定义全局自增ID
var atomicLong = 1

export function timeFix () {
  const time = new Date()
  const hour = time.getHours()
  return hour < 9
    ? '早上好'
    : hour <= 11
    ? '上午好'
    : hour <= 13
    ? '中午好'
    : hour < 20
    ? '下午好'
    : '晚上好'
}

export function isIE () {
  const bw = window.navigator.userAgent
  const compare = (s) => bw.indexOf(s) >= 0
  const ie11 = (() => 'ActiveXObject' in window)()
  return compare('MSIE') || ie11
}

/** 生成自增序列号（不重复） **/
export function genRowKey () {
  return new Date().getTime() + '_' + atomicLong++
}

// 获取当前时间--用来命名
export function handleTime () {
  const nowTime = new Date()
  const y = nowTime.getFullYear()
  const m = nowTime.getMonth() + 1
  const d = nowTime.getDate()
  return String(y) + String(m) + String(d)
}

// 获取当前时间--用来命名
export function download (blobUrl, name) {
  var a = document.createElement('a')
  a.style.display = 'none'
  a.download = `${name}_${handleTime()}.xls`
  a.href = blobUrl
  a.click()
  a.remove()
  window.URL.revokeObjectURL(blobUrl)
}
